/// @tags:
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

int const N = 1e5 + 5;

int n, m;
int w[N];

inline bool check(int i, int l, int r) {
  for (int j = i; j <= i + r - l; ++j) {
    if (w[j] + w[l + j - i] != w[i] + w[l]) return false;
  }
  return true;
}

inline int query(int l, int r) {
  int res = 0;
  for (int i = 1; i + r - l < l; ++i) res += check(i, l, r);
  for (int i = r + 1; i + r - l <= n; ++i) res += check(i, l, r);
  return res;
}

inline int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> w[i];
  cin >> m;
  for (int i = 1, l, r; i <= m; ++i) {
    cin >> l >> r;
    cout << query(l, r) << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("pair.in", "r", stdin);
  freopen("pair.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
